﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using YXShop.Common;

namespace YXShop.Web.admin.store
{
    public partial class store_list : System.Web.UI.Page
    {
        YXShop.BLL.Store.Store bll = new YXShop.BLL.Store.Store();
        protected void Page_Load(object sender, EventArgs e)
        {
            YXShop.Common.PromptInfo.Popedom("014001001");

            if(!IsPostBack)
            {
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    
                    string types = Request["Option"].Trim();
                    string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        if (YXShop.Common.PromptInfo.Message("014001003") != "ok")
                        {
                            bll.Delete(Convert.ToInt32(id));
                        }
                        else
                        {
                            Response.Write("no");
                        }
                    }
                    if (types == "delAll")
                    {
                        if (YXShop.Common.PromptInfo.Message("014001003") != "ok")
                        {
                        bll.DeleteAll(id);
                         }
                        else
                        {
                            Response.Write("no");
                        }
                    }
                    Response.End();
                    return;
                }
                this.lblList.Text = GetList("");
            }
        }

        #region 绑定
        private string GetList(string where)
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = bll.GetList(where);
            table.AddHeadCol("", "<input id=\"chall\" type=\"checkbox\" onclick=\"SelectAll(chall)\" />全选");
            table.AddHeadCol("","门店名称");
            table.AddHeadCol("","门店类型");
            table.AddHeadCol("","用户名称");
            table.AddHeadCol("","开始时间");
            table.AddHeadCol("","结束时间");
            //table.AddHeadCol("","审核状态");
            table.AddHeadCol("","操作");
            table.AddRow();
            if (dataPage.DataReader != null)
            {
                int curpage = ChangeHope.WebPage.PageRequest.GetInt("pageindex");
                if (curpage < 0)
                {
                    curpage = 1;
                }
                int count = 0;
                YXShop.Common.SysParameter sp=new YXShop.Common.SysParameter();

                while (dataPage.DataReader.Read())
                {                   
                    count++;
                    string No = (15 * (curpage - 1) + count).ToString();
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=\"" + dataPage.DataReader["sid"].ToString() + "\" />");
                    table.AddCol(dataPage.DataReader["storename"].ToString());
                    table.AddCol(ValuePair.GetStoreType(Convert.ToInt32(dataPage.DataReader["storetype"])));
                    table.AddCol(GetAdminUserName(Convert.ToInt32(dataPage.DataReader["adminid"])));
                    table.AddCol(dataPage.DataReader["startdate"].ToString());
                    table.AddCol(dataPage.DataReader["enddate"].ToString());
                    //table.AddCol(dataPage.DataReader["state"].ToString()=="0"?"未审核":"已审核");
                    string strUrl = YXShop.TemplateAction.Common.UrlStr("store_edit", "id=" + dataPage.DataReader["sid"].ToString(), "admin/store/");
                    table.AddCol("<a href=\""+strUrl+"\">查看/修改</a>&nbsp;<a href=\"#\" onclick='Del("+dataPage.DataReader["sid"]+")'>删除</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
        #endregion

        #region  获取数据
        /// <summary>
        /// 用户
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        private string GetAdminUserName(int adminuserId)
        {
            string url = YXShop.TemplateAction.Common.UrlStr("admin_edit", "adminid=" + adminuserId, "admin/member/");
            YXShop.BLL.Admin.Administrators adminuserBll = new YXShop.BLL.Admin.Administrators();
            YXShop.Model.Admin.Administrators adminuser = adminuserBll.GetModel(adminuserId);
            if (adminuser != null)
            {
                return "<a href=\""+url+"\">" + adminuser.Name + "</a>";
            }
            else
            {
                return "";
            }

        }

        #endregion

        #region 查询
        protected void linkQuery_Click(object sender, EventArgs e)
        {
            string strWhere="";               
            this.lblList.Text = GetList(strWhere);
        }
        #endregion

        #region 获取查询条件
        #endregion
    }
}
